package com.matrix.java.chap_03;

import java.util.Scanner;

/*
    某天是星期几
 */
public class Ex3_21 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter year:(e.g., 2012): ");
        int year = input.nextInt();
        System.out.print("Enter month:1-12: ");
        int month = input.nextInt();
        switch (month) {
            case 1:
                month = 13;
                year -= 1;
                break;
            case 2:
                month = 14;
                year -= 1;
        }
        System.out.print("Enter the day of the month:1-31: ");
        int day = input.nextInt();
        int q = day;
        int m = month;
        int j = Math.abs(year / 100);
        int k = year % 100;

        int h = (int) (q + (double) (26 * (m + 1)) / 10 + k + (double) (k + j) / 4 + 5 * j) % 7;
        String weekday = "";
        switch (h) {
            case 0:
                weekday = "Saturday";
                break;
            case 1:
                weekday = "Sunday";
                break;
            case 2:
                weekday = "Monday";
                break;
            case 3:
                weekday = "Tuesday";
                break;
            case 4:
                weekday = "Wednesday";
                break;
            case 5:
                weekday = "Thursday";
                break;
            case 6:
                weekday = "Friday";
        }
        System.out.println("Day of the week is " + weekday);
    }
}
